// 预加载脚本：用于实现主进程和渲染进程的通信，先于渲染进程，在浏览器环境中执行

const { contextBridge, ipcRenderer } = require('electron');

// 向渲染进程暴露安全的API
contextBridge.exposeInMainWorld('electronAPI', {
    // 获取当前用户
    getCurrentUser: () => ipcRenderer.invoke('get-current-user'),

    // 文章相关API
    getArticles: (options) => ipcRenderer.invoke('get-articles', options),
    getArticleById: (articleId) => ipcRenderer.invoke('get-article-by-id', articleId),
    getCategoryStats: () => ipcRenderer.invoke('get-category-stats'),
    getPopularArticles: (limit) => ipcRenderer.invoke('get-popular-articles', limit),

    addArticle: (articleData) => ipcRenderer.invoke('add-article', articleData),
    updateArticle: (articleId, articleData) => ipcRenderer.invoke('update-article', { articleId, articleData }),
    deleteArticle: (articleId) => ipcRenderer.invoke('delete-article', articleId),


    // 日志相关API
    getTimelineEntries: () => ipcRenderer.invoke('get-timeline-entries'),
    getTimelineEntryById: (id) => ipcRenderer.invoke('get-timeline-entry-by-id', id),
    addTimelineEntry: (entryData) => ipcRenderer.invoke('add-timeline-entry', entryData),
    updateTimelineEntry: (id, entryData) => ipcRenderer.invoke('update-timeline-entry', { id, entryData }),
    deleteTimelineEntry: (id) => ipcRenderer.invoke('delete-timeline-entry', id)
});